import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';

import 'nf_new_page.dart';
import 'nf_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with AutomaticKeepAliveClientMixin {
  List<String> bottomTitles = ['奈飞', '设置'];
  List<BottomNavigationBarItem> bottomItems = [];

  PageController _pageController;
  int _currentIndex = 0;

  @override
  void initState() {
    _pageController = PageController(initialPage: 0);

    bottomTitles.forEach((element) {
      bottomItems.add(BottomNavigationBarItem(
        icon: Icon(Icons.map),
        label: element,
      ));
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      body: PageView(
        controller: _pageController,
        onPageChanged: (i) {
          setState(() {
            _currentIndex = i;
          });
        },
        children: [
          NFNewMoviePage(),
          Container(
            child: Center(
              child: Text('2'),
            ),
          ),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white54,
        elevation: 0,
        items: bottomItems,
        currentIndex: _currentIndex,
        onTap: (i) => setState(() {
          _currentIndex = i;
          _pageController.animateToPage(i,
              duration: Duration(milliseconds: 200), curve: Curves.easeIn);
        }),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
